package com.example.mvpdemo.login;

import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.mvpdemo.R;
import com.example.mvpdemo.base.BaseActivity;

public class LoginActivity extends BaseActivity<LoginPresenter, Ilogin.VP> {
    private EditText etName;
    private EditText etPwd;
    private Button btLogin;

    @Override
    public Ilogin.VP getContract() {
        return new Ilogin.VP() {
            @Override
            public void requestLogin(String name, String pwd) {
                mPresenter.getContract().requestLogin(name, pwd);
            }

            @Override
            public void requestLoginResult(boolean loginStatusResult) {
                if (loginStatusResult) {
                    Toast.makeText(LoginActivity.this, "成狗", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(LoginActivity.this, "shibai", Toast.LENGTH_SHORT).show();
                }
            }
        };
    }

    @Override
    public void initView() {
        etName = findViewById(R.id.et_name);
        etPwd = findViewById(R.id.et_pwd);
        btLogin = findViewById(R.id.bt_login);


    }

    @Override
    public void initListener() {
        btLogin.setOnClickListener(this);
    }

    @Override
    public void initData() {

    }

    @Override
    public int getContentViewID() {
        return R.layout.activity_login;
    }

    @Override
    public LoginPresenter getmPresenterInstance() {
        return new LoginPresenter();
    }

    @Override
    public <ERROR> void responseError(ERROR error, Throwable throwable) {
        Toast.makeText(this, "error:" + error, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void destroy() {

    }

    @Override
    public void onClick(View view) {
        String name = etName.getText().toString();
        String pwd = etPwd.getText().toString();
//        requestLogin(name, pwd);

        getContract().requestLogin(name, pwd);

    }

//    @Override
//    public void requestLogin(String name, String pwd) {
//        try {
//            mPresenter.requestLogin(name, pwd);
//        } catch (Exception e) {
//            e.printStackTrace();
//            //保存到日志
//        }
//    }
//
//    @Override
//    public void requestLoginResult(boolean loginStatusResult) {
//        Toast.makeText(this, "成果", Toast.LENGTH_SHORT).show();
//    }
}
